<!--
*Author：COCO
 *代码由框架生成,任何更改都可能导致被代码生成器覆盖
 *业务请在@/extension/custom/custom/Base_DefectItem.js此处编写
 -->
<template>
    <div class="process-task-container">
          <view-grid ref="grid"
               :columns="columns"
               :detail="detail"
               :editFormFields="editFormFields"
               :editFormOptions="editFormOptions"
               :searchFormFields="searchFormFields"
               :searchFormOptions="searchFormOptions"
               :table="table"
               :extend="extend">
    </view-grid>

        <execution-plan-dialog
            v-model:visible="dialogVisible"
            :task-info="currentTaskInfo">
        </execution-plan-dialog>
    </div>
</template>

<script>
    import { defineComponent, ref, reactive, onMounted } from 'vue';
    import extend from "@/extension/productmanage/productmanage/processtask.js";
    import ExecutionPlanDialog from './components/ExecutionPlanDialog.vue';

    export default defineComponent({
        name: 'ProcessTask',
        components: {
            ExecutionPlanDialog
        },
        setup() {
            const dialogVisible = ref(false);
            const currentTaskInfo = ref(null);

            // 创建响应式的扩展对象
            const extendObj = reactive({
                ...extend,
                methods: {
                    ...extend.methods,
                    showExecutionPlan(row) {
                        console.log('Show execution plan for row:', row);
                        currentTaskInfo.value = {
                            ProcessTaskId:row.ProcessTaskId,
                            taskCode: row.ProcessTaskCode,
                            batchCode: row.ProductionBatchCode,
                            taskStatus: row.TaskStatus,
                            taskPriority: row.TaskPriority,
                            productionBatchCode: row.ProductionBatchCode
                        };
                        dialogVisible.value = true;
                    }
                }
            });

            // 表格配置
            const tableConfig = {
                key: 'ProcessTaskId',
                footer: "Foots",
                cnName: '工序任务',
                name: 'productmanage/productmanage/ProcessTask',
                url: "/ProcessTask/",
                sortName: "CreateDate",
                height: 0,
                defaultLoadPage: true,
                defaultSearchForm: true
            };

            // 编辑表单字段
            const editFormFields = {
                "ProcessTaskCode": "",
                "TaskPriority": "",
                "TaskStatus": "",
                "ProductionBatchCode": "",
                "ProductId": "",
                "ProcessmanagementmoduleId": "",
                "ProductionWorkOrderId":[]
            };

            // 编辑表单选项
            const editFormOptions = [[
                {
                    "title": "工序任务编号",
                    "field": "ProcessTaskCode",
                    "type": "text",
                    "placeholder": "请输入，忽略将自动生成",
                    "required": true
                },
                  {"title":"工单编号","field":"ProductionWorkOrderId","type":"select","dataKey":"MyWorkOrder","data":[]},
                //  {
                //     "field": 'ProductionWorkOrderId',
                //     "title": '工单编号',
                //     "type": 'select',
                //     "dataKey": "MyWorkOrder",
                //     "required": true,
                //     "data": []
                // },
                {
                    "title": "任务状态",
                    "required": true,
                    "field": "TaskStatus",
                    "type": "select",
                    "dataKey": "TaskStatus",
                    "data": []
                }
            ],[
                {
                    "title": "优先级",
                    "field": "TaskPriority",
                    "type": "select",
                    "dataKey": "TaskPriority",
                    "required": true,
                    "data": []
                },
                {
                    "title": "生产批次",
                    "field": "ProductionBatchCode",
                    "type": "text",
                    "required": true
                }
            ],[
                {
                    "title": "成品主键",
                    "field": "ProductId",
                    "type": "select",
                    "dataKey": "WProductInfo",
                    "required": true,
                    "data": []
                },
                {
                    "title": "工序管理主键",
                    "field": "ProcessmanagementmoduleId",
                    "type": "select",
                    "dataKey": "ProcessXu",
                    "required": true,
                    "data": []
                }
            ]];

            // 搜索表单字段和选项
            const searchFormFields = {
                "ProcessTaskCode": "",
                "TaskStatus": "",
                "ProductionBatchCode": ""
            };

            const searchFormOptions = [[
                {
                    "title": "工序任务编号",
                    "field": "ProcessTaskCode",
                    "type": "like"
                },
                {
                    "title": "任务状态",
                    "field": "TaskStatus",
                    "type": "select",
                    "dataKey": "TaskStatus",
                    "data": []
                },
                {
                    "title": "生产批次",
                    "field": "ProductionBatchCode",
                    "type": "like"
                }
            ]];

            // 表格列配置
            const columns = ref([ {
                    field: 'ProcessTaskId',
                    title: '工序任务表主键ID',
                    type: 'guid',
                    width: 110,
                    hidden: true,
                    readonly: true,
                    require: true,
                    align: 'left'
                },
                {
                    field: 'ProcessTaskCode',
                    title: '工序任务编号',
                    type: 'string',
                    width: 180,
                    align: 'left',
                    sort: true,
                    required: true
                },
                    {field:'ProductionWorkOrderId',title:'工单编号',sort:true,type:'guid',bind:{ key:'MyWorkOrder',data:[]},width:130,align:'left'},
                // {
                //     field: 'ProductionWorkOrderId',
                //     title: '工单编号',
                //     type: 'guid',
                //        bind: {
                //         key: 'MyWorkOrder',
                //         data: [],
                //         // textField: 'text',
                //         // valueField: 'value'
                //     },
                //     width: 180,
                //     align: 'left',
                //     sort: true,
                //     required: true
                // },
                {
                    field: 'TaskStatus',
                    title: '任务状态',
                    type: 'int',
                    bind: {
                        key: 'TaskStatus',
                        data: [],
                        textField: 'text',
                        valueField: 'value'
                    },
                    width: 120,
                    align: 'left',
                    sort: true,
                    required: true
                },
                {
                    field: 'TaskPriority',
                    title: '优先级',
                    type: 'int',
                    bind: {
                        key: 'TaskPriority',
                        data: [],
                        textField: 'text',
                        valueField: 'value'
                    },
                    width: 100,
                    align: 'left'
                },
                {
                    field: 'ProductionBatchCode',
                    title: '生产批次',
                    type: 'string',
                    width: 180,
                    align: 'left',
                    sort: true,
                    required: true
                },
                {
                    field: 'ProductId',
                    title: '成品主键',
                    type: 'string',
                    bind: { 
                        key: 'WProductInfo',
                        data: [],
                        textField: 'text',
                        valueField: 'value'
                    },
                    width: 180,
                    align: 'left',
                    required: true
                },
                {
                    field: 'ProcessmanagementmoduleId',
                    title: '工序管理主键',
                    type: 'string',
                    bind: {
                        key: 'ProcessXu',
                        data: [],
                        textField: 'text',
                        valueField: 'value'
                    },
                    width: 180,
                    align: 'left',
                    required: true
                },
                {
                    field: 'CreateDate',
                    title: '创建时间',
                    type: 'datetime',
                    width: 150,
                    align: 'left',
                    sort: true
                },
                {
                    field: 'Creator',
                    title: '创建人',
                    type: 'string',
                    width: 130,
                    align: 'left'
                },
                {
                    title: '操作',
                    field: 'operation',
                    width: 100,
                    align: 'center',
                    render: (h, { row }) => {
                        return h('el-button', {
                            props: { type: 'text', size: 'small' },
                            style: { color: '#409EFF' },
                            onClick: () => extendObj.methods.showExecutionPlan(row)
                        }, '生产执行');
                    }
                }
            ])

            // 明细配置
            const detail = {
                cnName: "#detailCnName",
                table: "#detailTable",
                columns: [],
                sortName: "",
                key: ""
            };

            return {
                extendObj,
                dialogVisible,
                currentTaskInfo,
                table: tableConfig,
                editFormFields,
                editFormOptions,
                searchFormFields,
                searchFormOptions,
                columns,
                detail
            };
        }
    });
</script>

<style scoped>
.process-task-container {
    width: 100%;
    height: 100%;
    position: relative;
    padding: 15px;
}

.process-task-header {
    margin-bottom: 15px;
}

.process-task-header h2 {
    font-size: 18px;
    color: #333;
    margin: 0;
}
</style>
